//
//  TomamaUI.m
//  Tomama
//
//  Created by qianfeng on 15/12/16.
//  Copyright (c) 2015年 ZhangLuJie. All rights reserved.
//

#import "TomamaUI.h"

@interface TomamaUI()

@property (nonatomic, strong) UIAlertController *alert;

@end

@implementation TomamaUI

+(CGFloat)getStringWeithtWith:(NSString *)str andHeigth:(CGFloat )h andFont:(UIFont *)font
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, h) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil] context:nil];
    return rect.size.width;
}

+(CGFloat)getStringHeightWith:(NSString *)str andWeith:(CGFloat )w andFont:(UIFont *)font
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(w, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil] context:nil];
    return rect.size.height;
}

+(CGFloat)getStringHeightWith:(NSString *)str andWeith:(CGFloat )w andFont:(UIFont *)font andLineSpacing:(CGFloat)lineSpacing
{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = lineSpacing;
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle};
    CGSize size = [str boundingRectWithSize:CGSizeMake(w, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}

+(NSString *)deleteChar:(NSString *)charStr inString:(NSString *)string
{
    return [[string componentsSeparatedByString:charStr] componentsJoinedByString:@""];
}

+(NSString*)stringToDataString:(NSString *)str andString:(NSString *)gehsi
{
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:[str doubleValue]/1000];
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:gehsi];
    
    NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
    return currentDateStr;
}

+(NSString*)weekDayStr:(NSString *)format
{
    NSString *weekDayStr = nil;
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    
    NSString *str = format;
    if (str.length >= 10) {
        NSString *nowString = [str substringToIndex:10];
        NSArray *array = [nowString componentsSeparatedByString:@"-"];
        if (array.count == 0) {
            array = [nowString componentsSeparatedByString:@"/"];
        }
        if (array.count >= 3) {
            NSInteger year = [[array objectAtIndex:0] integerValue];
            NSInteger month = [[array objectAtIndex:1] integerValue];
            NSInteger day = [[array objectAtIndex:2] integerValue];
            [comps setYear:year];
            [comps setMonth:month];
            [comps setDay:day];
        }
    }
    
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *_date = [gregorian dateFromComponents:comps];
    NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:_date];
    NSInteger week = [weekdayComponents weekday];
//    week ++;
    switch (week) {
        case 1:
            weekDayStr = @"星期日";
            break;
        case 2:
            weekDayStr = @"星期一";
            break;
        case 3:
            weekDayStr = @"星期二";
            break;
        case 4:
            weekDayStr = @"星期三";
            break;
        case 5:
            weekDayStr = @"星期四";
            break;
        case 6:
            weekDayStr = @"星期五";
            break;
        case 7:
            weekDayStr = @"星期六";
            break;
        default:
            weekDayStr = @"";  
            break;  
    }  
    return weekDayStr;  
}

+(UILabel *)createLabel:(CGRect)cg textAligment:(NSInteger)aligment font:(UIFont *)font textColor:(UIColor *)textColor text:(NSString *)text
{
    UILabel *label = [[UILabel alloc]initWithFrame:cg];
    label.textAlignment = aligment;
    label.font = font;
    label.textColor = textColor;
    label.text = text;
    return label;
}

+(UIImageView *)createImageView:(CGRect)cg backGroundImageV:(NSString *)imageName
{
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:cg];
    imageV.image = [UIImage imageNamed:imageName];
    return imageV;
}

+(UIButton *)createButton:(NSInteger)buttonType Frame:(CGRect)cg targ:(id)targe sel:(SEL)sel titleColor:(UIColor *)titleColor font:(UIFont*)font title:(NSString *)title  image:(NSString *)imageName backGroundImage:(NSString*)backImageName
{
    UIButton *button = [UIButton buttonWithType:buttonType];
    button.frame = cg;
    [button setTitle:title forState:UIControlStateNormal];
    if (titleColor) {
        [button setTitleColor:titleColor  forState:UIControlStateNormal];
    }
    if (imageName) {
        [button setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
    if (backImageName) {
        [button setBackgroundImage:[[UIImage imageNamed:backImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
    if (font) {
        button.titleLabel.font = font;
    }
    [button addTarget:targe action:sel forControlEvents:UIControlEventTouchUpInside];
    return button;
}

+(int)getTimeWithDate1:(NSDate *)date1 andDate2:(NSDate *)date2
{
    NSCalendar *cal = [NSCalendar currentCalendar];
    
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    
    NSDateComponents *d = [cal components:unitFlags fromDate:date1 toDate:date2 options:0];
    
    long sec = [d hour]*3600+[d minute]*60+[d second];
    
    return (int)sec;
}

+ (NSDate *)getDateWithString:(NSString *)dateStr
{
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    formater.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate* date = [formater dateFromString:dateStr];
    NSTimeZone * zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:date];
    NSDate * nowDate = [date dateByAddingTimeInterval:interval];
    return nowDate;
}

+ (NSDate *)getDateWithStringNo8:(NSString *)dateStr
{
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    formater.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate* date = [formater dateFromString:dateStr];
    return date;
}

+(NSString *)dateTostiring:(NSDate *)date andString:(NSString *)geshi
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:geshi];
    NSString *currentDateStr = [dateFormatter stringFromDate:date];
    return currentDateStr;
}

+ (NSDate *)getNowDate
{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSTimeZone * zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:currentDate];
    NSDate * nowDate = [currentDate dateByAddingTimeInterval:interval];
    return nowDate;
}

+(void)creatAlertWithTarget:(UIViewController *)vc message:(NSString *)message timeInterval:(CGFloat)timeInterval
{
    
    if ([message isEqual:[NSNull null]]) {//!message || [message isEqual:[NSNull null]]
        message = @"请求超时";
    }
    UILabel *label = [TomamaUI createLabel:CGRectMake(vc.view.frame.size.width/2 - ([TomamaUI getStringWeithtWith:message andHeigth:44*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6)/2, vc.view.frame.size.height/2 - 22*screenW_6, [TomamaUI getStringWeithtWith:message andHeigth:44*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6, 44*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:13*screenW_6] textColor:[UIColor whiteColor] text:message];
    if (label.frame.size.width > SCREENW*2/3) {
        label.frame = CGRectMake(vc.view.frame.size.width/2 - SCREENW*1/3, vc.view.frame.size.height/2 - ([TomamaUI getStringHeightWith:message andWeith:SCREENW*2/3 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6)/2, SCREENW*2/3, [TomamaUI getStringHeightWith:message andWeith:SCREENW*2/3 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6);
    }
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor blackColor];
    label.layer.masksToBounds = YES;
    label.layer.cornerRadius = 3;
    label.alpha = 0.8;
    [vc.view addSubview:label];
    [UIView animateWithDuration:timeInterval animations:^{
        label.alpha = 0;
    } completion:^(BOOL finished) {
        [label removeFromSuperview];
    }];
}

+(void)creatAlertWithTarget:(UIViewController *)vc message:(NSString *)message timeInterval:(CGFloat)timeInterval block:(void (^)())block
{
    UILabel *label = [TomamaUI createLabel:CGRectMake(vc.view.frame.size.width/2 - ([TomamaUI getStringWeithtWith:message andHeigth:44*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6)/2, vc.view.frame.size.height/2 - 22*screenW_6, [TomamaUI getStringWeithtWith:message andHeigth:44*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6, 44*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:13*screenW_6] textColor:[UIColor whiteColor] text:message];
    if (label.frame.size.width > SCREENW*2/3) {
        label.frame = CGRectMake(vc.view.frame.size.width/2 - SCREENW*1/3, vc.view.frame.size.height/2 - ([TomamaUI getStringHeightWith:message andWeith:SCREENW*2/3 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6)/2, SCREENW*2/3, [TomamaUI getStringHeightWith:message andWeith:SCREENW*2/3 andFont:[UIFont systemFontOfSize:13*screenW_6]] + 20*screenW_6);
    }
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor blackColor];
    label.layer.masksToBounds = YES;
    label.layer.cornerRadius = 3;
    label.alpha = 0.8;
    [vc.view addSubview:label];
    vc.view.userInteractionEnabled = NO;
    [UIView animateWithDuration:timeInterval animations:^{
        label.alpha = 0;
    } completion:^(BOOL finished) {
        [label removeFromSuperview];
        vc.view.userInteractionEnabled = YES;
        block();
    }];
}

+(void)loadWedImageWithImageView:(UIImageView *)imageV andUrl:(NSString *)url
{
    if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:url]) {
        imageV.image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:url];
    }
    else{
        [imageV sd_setImageWithURL:[NSURL URLWithString:url]];
    }
}

+(UIImage *)compressImage:(UIImage *)sourceImage toTargetWidth:(CGFloat)targetWidth
{
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetHeight = (targetWidth / width) * height;
    UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));
    [sourceImage drawInRect:CGRectMake(0, 0, targetWidth, targetHeight)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

+(UIImage *)addFilterWithImage:(UIImage *)originImage andFilterName:(NSString *)filterName
{
    //将UIImage转换成CIImage
    CIImage *ciImage = [[CIImage alloc] initWithImage:originImage];
    //创建滤镜
    CIFilter *filter = [CIFilter filterWithName:filterName keysAndValues:kCIInputImageKey, ciImage, nil];
    //已有的值不改变，其他的设为默认值
    [filter setDefaults];
    //获取绘制上下文
    CIContext *context = [CIContext contextWithOptions:nil];
    //渲染并输出CIImage
    CIImage *outputImage = [filter outputImage];
    //创建CGImage句柄
    CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
    //获取图片
    UIImage *image = [UIImage imageWithCGImage:cgImage];
    //释放CGImage句柄
    CGImageRelease(cgImage);
    return image;
}

+ (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height
{
    CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
    UIGraphicsBeginImageContext(r.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, r);
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}

+(UIViewController *)getTopVC
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    
    if ([topVC isKindOfClass:[UITabBarController class]]) {
        UITabBarController *tabBarVC = (UITabBarController *)topVC;
        UINavigationController *navi = tabBarVC.viewControllers[tabBarVC.selectedIndex];
        
        return [navi.viewControllers lastObject];
    }
    else if ([topVC isKindOfClass:[UINavigationController class]])
    {
        UINavigationController *navi = (UINavigationController *)topVC;
        return [navi.viewControllers lastObject];
    }
    else{
        return topVC;
    }
}

+(NSString *)writeToFileWithPhoto:(UIImage *)photo
{
    NSString *tempPath = NSTemporaryDirectory();
    NSString *filePath = [tempPath stringByAppendingPathComponent:[[NSUUID UUID].UUIDString stringByAppendingString:@".png"]];
    NSData *imageData = UIImagePNGRepresentation(photo);
    BOOL isFinish = [imageData writeToFile:filePath atomically:YES];
    
    if (isFinish) {
        return filePath;
    }
    else{
        return @"0";
    }
}

+(NSString *)writeToFileWithPath:(NSString *)filePath
{
    NSData *imageData = [NSData dataWithContentsOfFile:filePath];
    NSString *tempPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *path = [tempPath stringByAppendingPathComponent:[[NSUUID UUID].UUIDString stringByAppendingString:@".png"]];
    BOOL isFinish = [imageData writeToFile:path atomically:YES];
    if (isFinish) {
        return path;
    }
    else{
        return @"0";
    }
}

+(void)DeleteFileWithPath:(NSString *)filePath
{
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}

+(NSString *)replaceHTMLWithText:(NSString *)text
{
    text = [text stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
    text = [text stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    text = [text stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    text = [text stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
    text = [text stringByReplacingOccurrencesOfString:@"&#39;" withString:@"\'"];
    text = [text stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
    text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
    return text;
}

+(void)openGPS
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"定位权限未开启" message:@"是否开启定位" preferredStyle:  UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
       
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSURL *url = [NSURL URLWithString:@"prefs:root=com.lppz.mobile.ios.outsales"];
        double version = [[UIDevice currentDevice].systemVersion doubleValue];
        //判定系统版本。
        if(version >= 8.0f){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }
        else {
            [[UIApplication sharedApplication] openURL:url];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        });
    }]];
    [[TomamaUI getTopVC] presentViewController:alert animated:true completion:nil];
}

+(BOOL)isEnabledLocationServices{
//    if ([CLLocationManager locationServicesEnabled] == NO) {
//        return NO;
//    } else {
//        CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
//        if(authorizationStatus == kCLAuthorizationStatusDenied || authorizationStatus == kCLAuthorizationStatusRestricted){
//            return NO;
//        } else {
//            return YES;
//        }
//    }
    return NO;
}

/**
 *  计算UILabel的高度(带有行间距的情况)
 *  @param text  内容
 *  @param font  字体
 *  @param width 宽度
 *  @return 高度
 *  @param zpace  字间距 --> @10 这样设置  默认的话设置 0 就ok
 */
+(CGFloat)getSpaceLabelHeight:(NSString*)text withFont:(UIFont*)font withWidth:(CGFloat)width withSpace:(CGFloat)space withZspace:(NSNumber *)zpace{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode =NSLineBreakByCharWrapping;
    paraStyle.alignment =NSTextAlignmentLeft;
//    paraStyle.lineSpacing = space;
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent =0.0;
    paraStyle.paragraphSpacingBefore =0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic;
    CGFloat height;
    CGFloat oneHeight;
    CGFloat rowHeight;
    // 设置文本偏移量
//    CGFloat offset = -(1.0/3 * space) - 1.0/3;
    if (zpace == 0) {
        dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@1.5f
               };
    }else {
        dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:zpace,
               };
        // 计算文本的高度
        oneHeight = [@"这样貌似解决了" boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:dic context:nil].size.height;
        rowHeight = [text?text:@"" boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:dic context:nil].size.height;
        if (rowHeight>oneHeight) {
            height = rowHeight;
            paraStyle.lineSpacing = space; //设置行间距
            dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:zpace,
                   };
        }
        else{
            height = oneHeight;
            paraStyle.lineSpacing = 0; //设置行间距
            dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:zpace,
                   };
        }
    }
    CGSize size = [text?text:@"" boundingRectWithSize:CGSizeMake(width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil].size;
    return size.height;
}

+(LPPZStatusType)getWebStatus
{
    // 状态栏是由当前app控制的，首先获取当前app
    UIApplication *app = [UIApplication sharedApplication];
    NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
    int type = 0;
    for (id child in children) {
        if ([child isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
            type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
        }
    }
    LPPZStatusType stateType = notReachable;
    switch (type) {
        case 0:
            stateType = notReachable;
            break;
        case 1:
            stateType = towG;
            break;
        case 2:
            stateType = threeG;
            break;
            
        case 3:
            stateType = fourG;
            break;
        case 4:
            stateType = LTE;
            break;
        case 5:
            stateType = wifi;
            break;
        default:
            break;
    }
    
    return stateType;
}

+ (BOOL)valiMobile:(NSString *)mobile{
    if (mobile.length != 11)
    {
        return NO;
    }
    /**
     * 手机号码:
     * 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[0, 1, 6, 7, 8], 18[0-9]
     * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
     * 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186
     * 电信号段: 133,149,153,170,173,177,180,181,189
     */
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\\d{8}$";
    /**
     * 中国移动：China Mobile
     * 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
     */
    NSString *CM = @"^1(3[4-9]|4[7]|5[0-27-9]|7[08]|8[2-478])\\d{8}$";
    /**
     * 中国联通：China Unicom
     * 130,131,132,145,155,156,170,171,175,176,185,186
     */
    NSString *CU = @"^1(3[0-2]|4[5]|5[56]|7[0156]|8[56])\\d{8}$";
    /**
     * 中国电信：China Telecom
     * 133,149,153,170,173,177,180,181,189
     */
    NSString *CT = @"^1(3[3]|4[9]|53|7[037]|8[019])\\d{8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    
    if (([regextestmobile evaluateWithObject:mobile] == YES)
        || ([regextestcm evaluateWithObject:mobile] == YES)
        || ([regextestct evaluateWithObject:mobile] == YES)
        || ([regextestcu evaluateWithObject:mobile] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

@end
